package com.weme.mine.activity

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.resources.R
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar
import com.weme.common.util.setGradientText
import com.weme.common.util.setOnFastClickListener
import com.weme.common.arouter.ARouterPaths
import com.weme.common.base.BaseMvvmActivity
import com.weme.common.util.UtilsApp
import com.weme.common.view.CustomDialogFragment
import com.weme.mine.databinding.ActivityAboutBinding
import com.weme.mine.viewmode.AboutViewMode
import dev.kratos.api.user_server.v1.DeleteAccountRequest

@Route(path = ARouterPaths.MINE_ABOUT_ACTIVITY)
class AboutActivity : BaseMvvmActivity<ActivityAboutBinding, AboutViewMode>() {
    override fun initView(savedInstanceState: Bundle?) {
        ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR).titleBar(mBinding.customTopNavigationBar).init()
        mBinding.tvAppName.setGradientText(R.color.startColor, R.color.endColor)
        mBinding.tvVersion.text = String.format(getString(R.string.about_version),UtilsApp.getVersionName())
        mBinding.srvDel.setOnFastClickListener {
            showCustomDialog(
                title = getString(R.string.about_delete_account),
                content = getString(R.string.about_delete_content1),
                positiveButtonText = getString(R.string.cancel),
                negativeButtonText = getString(R.string.yes)
            ) { result ->
                when (result) {
                    0 -> showCustomDialog(
                        title = getString(R.string.about_delete_account),
                        content = getString(R.string.about_delete_content2),
                        positiveButtonText = getString(R.string.cancel),
                        negativeButtonText = getString(R.string.yes)
                    ) { result1 ->
                        when (result1) {
                            0 -> showCustomDialog(
                                title = getString(R.string.about_delete_account),
                                content = getString(R.string.about_delete_content3),
                                positiveButtonText = getString(R.string.ok),
                                negativeButtonText = ""
                            ) { _ ->

                                    viewModel.deleteAccount(DeleteAccountRequest.newBuilder().build())

                            }
                            else -> {
                                // 取消按钮点击事件
                            }
                        }
                    }
                    else -> {
                        // 取消按钮点击事件
                    }
                }
            }
        }


    }


    override fun onDestroy() {
        super.onDestroy()

    }

    private fun showCustomDialog(
        title: String,
        content: String,
        positiveButtonText: String,
        negativeButtonText: String,
        listener: (Int) -> Unit
    ) {
        val dialog = CustomDialogFragment.newInstance(
            title = title,
            content = content,
            positiveButtonText = positiveButtonText,
            negativeButtonText = negativeButtonText,
            listener = object : CustomDialogFragment.DialogClickListener {
                override fun onPositiveButtonClick() {
                    listener.invoke(1)
                }

                override fun onNegativeButtonClick() {
                    listener.invoke(0)
                }
            }
        )
        dialog.show(supportFragmentManager, "CustomDialog")
    }

    override fun onResume() {
        super.onResume()
        mBinding.scanEffectView.startLight()
    }

    override fun onPause() {
        super.onPause()
        mBinding.scanEffectView.stopLight()
    }

    override fun getViewModelClass(): Class<AboutViewMode> = AboutViewMode::class.java

    
}